import adminRoute from '@/router/routes/admin'

const routes = adminRoute.children

const initState = {
  navto: '',
  navtitle: ''
}

const reducer = (state = initState, { type, data }) => {
  // 修改导航信息
  if ('setNavItem' === type) {
    let route = routes.find(item => item.path === data)
    let navto = ''
    let navtitle = ''
    if (route) {
      navto = data
      navtitle = route.title
    }
    return { ...state, navto, navtitle }
  }

  return state
}

export default reducer
